<?php
class MailUtility{

	private $_senderEmail = "support@pramodthakur.com";
	private $_senderName = "Pramod Thakur";

	private $_bccEmail = "info@pramodthakur.com";
	private $_bccName = "Pramod Thakur";

	public function __construct() {}

	public function sendSignupVerifyMail( $name, $email ) {
		if( $name == '' || $email == '' ){
			return false;
		}
		try{			
			//$subject = '[Corfirm Email] Welcome to urexpenses';
			$subject = ucwords( $name ) . " Welcome to urexpenses";

			//$messageHead = '[Corfirm Email] Welcome to urexpenses';
			$messageHead = ucwords( $name ) . 'Welcome to urexpenses';

			$mailBody = 'welcome to urexpenses...';

			//$mailBodyHtml = $this->generateEmailTemplate( $messageHead, $mailBody );
			$mailBodyHtml = $messageHead . '<br/>' . $mailBody;

			
			$objMail = new Mail();
			$objMail->setFrom( $this->_senderEmail, $this->_senderName )->addRecipient( $email, $name );
			$objMail->bcc( $this->_bccEmail, $this->_bccName );
			$objMail->buildMail( $subject, $messageHead . "\n". strip_tags( $mailBody ), $mailBodyHtml );
			$result = $objMail->sendMail();
			return $result;
		}catch( Exception $ex ){
			throw $ex;
		}
	}

	public function sendLoginAlertMail( $name, $email, $login ) {
		if( $name == '' || $email == '' ){
			return false;
		}
		try{			
			//$subject = '[Corfirm Email] Welcome to urexpenses';
			$subject = 'Hi ' . ucwords( $name ) . ", an activity of login to urexpenses site are seen";

			//$messageHead = '[Corfirm Email] Welcome to urexpenses';
			$messageHead = 'Hi ' . ucwords( $name ) . '<br/>';

			$mailBody = 'Dear customer an activity of login to urexpenses site are noted on ' . date( 'Y-m-d H:i:s' ) . ', please check or it is by you then ignore.';
			$mailBody .= "<br/><br/><br/>Thanks,<br/>Team URExpenses.";
			//$mailBodyHtml = $this->generateEmailTemplate( $messageHead, $mailBody );
			$mailBodyHtml = $messageHead . '<br/>' . $mailBody;

			// send mail
			$objMail = new Mail();
			$objMail->setFrom( $this->_senderEmail, $this->_senderName )->addRecipient( $email, $name );
			$objMail->bcc( $this->_bccEmail, $this->_bccName );
			$objMail->buildMail( $subject, $messageHead . "\n". strip_tags( $mailBody ), $mailBodyHtml );
			$result = $objMail->sendMail();
			return $result;
		}catch( Exception $ex ){
			throw $ex;
		}
	}
	/**
	 * Transaction email template
	 */
	private function generateEmailTemplate( $messageHead, $message, $image = false ){
		$template = new PHPTAL( TPL_PATH . 'email_template_transaction.tpl.php' );
		$template->messageHead = $messageHead;
		$template->message = $message;
		$template->image = $image;
		$template->homepath = HOME_PATH;
		return $template->execute();
	}
	
}